package com.tyut.musicdreamer.framework.starter.common.config;

import com.tyut.musicdreamer.framework.starter.common.tookit.SpringUtil;
import com.tyut.musicdreamer.framework.starter.common.tookit.StringRedisTemplateUtil;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * Common模块自动配置类
 */
@Configuration
@ComponentScan(basePackages = {"com.tyut.musicdreamer.framework.starter.common"})
@EnableConfigurationProperties(RedisDistributedProperties.class)
public class CommonAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SpringUtil springUtils() {
        return new SpringUtil();
    }

    @Bean
    @ConditionalOnMissingBean
    public RedisDistributedProperties redisDistributedProperties() {
        return new RedisDistributedProperties();
    }

    @Bean
    @ConditionalOnMissingBean
    // 静态代理模式: Redis 客户端代理类增强
    public StringRedisTemplateUtil stringRedisTemplateUtil(StringRedisTemplate stringRedisTemplate, RedissonClient redissonClient,
                                                           RedisDistributedProperties redisDistributedProperties) {
        return new StringRedisTemplateUtil(stringRedisTemplate, redisDistributedProperties, redissonClient);
    }
}
